<?php
/**
 * Description of ${name}
 *
 * @author ${user}
 */
class PACTS_config_variables extends pactUser{
    public $SoftwareShortName = "PACTS";
    //    public $SoftwareLongName = "People At Church Tracking System";
    public $SoftwareLongName = "";
    public $SoftwareVersion = "1.1 beta r";
    public $SoftwareDate = "Jan 2009";
    public $SoftwareUserName = "{Software USER NAME}";
    public $SoftwareAuthorName = "Colin Todd";
    public $SoftwareLogo = "furniture/design/logoPACTS.gif";
    //public $SoftwareLogo = "furniture/design/pacts_beta_logo.png";
    public $SoftwareLogoPDF = "furniture/design/logoGPAC_PDF.gif";
    public $SoftwareWebsite = "http://code.google.com/p/pacts/";

    // MYSQL details
    public $dbname     = "pacts5";  // Name of your database.
    public $dbserver   = "127.0.0.1";  // Host name. Usually localhost.
    public $dbuser     = "pactsuser";  // Your mySQL username.
    public $dbpass     = "passw0rd";  // Your mySQL password
    public $table      = "Individual"; // The table used in the database. Leave as is if using the standard name.

    public $KindergartenAgeCount = 5;// Children will usually start Kindergarten at age 5

    public $intDefaultInternationalTelephoneCode = 61;
    public $DefaultCountry = "Australia";

    public $intDefaultTelephoneSTDCode = '02'; //for 02 phone area
    public $intDefaultSTDLength = 2;  // ie without leading zero
    public $bNoLeadingZeroInSTD = FALSE;
    public $intDefaultNonMobileTelephoneNumberLength = 8;
    public $intDefaultMobileTelephoneNumberLength = 10; // includes the leading 0 which isn't required when an international number

    public $page_view_404 = "_content/Error404.php";
    public $page_view_500 = "Error500.php";

    public $session_timeout_seconds = 3600;
    // table names
    public $familytablename     = "Family";
    public $individualtablename = "Individual";
    public $userstablename  = "Users";
    public $usergrouptablename  = "UserGroup";
    public $gendertablename = "Gender";
    public $worktypetablename = "WorkType";
    public $roletypetablename = "RoleType";
    public $titletablename = "Title";
    public $educationgradetablename = "EducationGrade";
    public $fmlycommenttexttablename = "fmlycommenttext";
    public $metadatatablename ="MetaData";
    public $residentialcountrytablename = "ResidentialCountry";
    public $bookletfootermessagetablename = "BookletFooterMessage";
    public $agerangetablename     = "AgeRange";
    public $churchdeparturereasontablename     = "ChurchDepartureReason";
    public $churchintroductionmethodtablename     = "ChurchIntroductionMethod";
    public $educationinstitutiontablename = "EducationalInstitution";
    public $maritalstatustablename     = "MaritalStatus";
    public $postcodetablename     = "Postcode";
    public $postcodesuburbmappingtablename     = "PostcodeSuburbMapping";
    public $premisetypetablename     = "PremiseType";
    public $statetablename = "State";
    public $suburbtablename = "Suburb";
    public $streettypetablename     = "StreetType";

    public $URLmessage;
    // Login information


    // Do not edit below this line
    //public $version  = "1.1";

    //time variables
    public $startpageload;
    public $endpageload;

    public $DefaultRedirectLocation="Home";

    public $color="";

    public $content1_mouseover= " onMouseOver=\"this.style.backgroundColor='#EEFFFF'\" onMouseOut=\"this.style.backgroundColor='#EEFFFF'\" ";
    public $content2_mouseover= " onMouseOver=\"this.style.backgroundColor='#DDDDDD'\" onMouseOut=\"this.style.backgroundColor='#EEFFFF'\" ";

    public $titleTxtClass = " class=\"txtbotH\" ";
    public $JavascriptKeyPress = "onkeypress=\"return tE(event,this.form)\"";

    public $nav_width1 =20; // one entry per line
    public $nav_width2 =7; // two entry per line
    public $nav_width3 =3; // admin nav

    public $getNumAuditRecords = 20; // for logs screen. number of records to get at a time

    public $FontCharCountToSizeRatio = 0.49; # used on PDF reports to centre footer text

    public $textbox = "textbox";
    public $textareabox = "textareabox";
    public $datebox = "datebox";
    public $enumcheckbox = "enumcheckbox";
    public $imagebox = "imagebox";
    public $timebox = "timebox";
    public $timedatebox = "timedatebox";
    public $yearbox = "yearbox";

    public $inputREADONLY = ' disabled="disabled" '; // or DISABLED READONLY


    public $intTextAreaColSize = 35;
    public $intMaxInputBoxSize = 51;
    public $intTextAreaDefaultCharCount = 200;
    public $intTextAreaLargeCharCount = 1000;

    //
    // Setup for lookup tables
    //

    public $RoleTypeTable =    array('Table' => "RoleType",   'Key' => "RoleTypeCode", 'Description' => "Description");
    public $GenderCodeTable =    array('Table' => "Gender",    'Key' => "GenderCode", 'Description' => "Description");
    public $TitleTable =     array('Table' => "Title",    'Key' => "Title", 'Description' => "Description");
    public $ChurchIntroductionMethodTable = array('Table' => "ChurchIntroductionMethod",'Key' => "ChurchIntroductionMethod", 'Description' => "Description");
    public $ChurchDepartureReasonTable =     array('Table' => "ChurchDepartureReason",    'Key' => "ChurchDepartureReason", 'Description' => "Description");
    public $MaritalStatusCodeTable =  array('Table' => "MaritalStatus",  'Key' => "MaritalStatusCode", 'Description' => "Description");
    public $EducationInstitutionTable = array('Table' => "EducationalInstitution",'Key' => "EducationalInstitutionName", 'Description' => "EducationalInstitutionName", 'Description2' => "EducationalInstitutionType");
    public $AgeRangeTable =    array('Table' => "AgeRange",   'Key' => "AgeRange", 'Description' => "Description");
    public $PremiseTypeTable =    array('Table' => "PremiseType",   'Key' => "PremiseTypeCode", 'Description' => "Description");
    public $StreetTypeCodeTable =   array('Table' => "StreetType",   'Key' => "StreetTypeCode", 'Description' => "Description");
    public $CountryTable =     array('Table' => 'Country',    'Key' => "Country", 'Description' => "Country");
    public $WorkTypeCodeTable =   array('Table' => "WorkType",   'Key' => "WorkTypeCode",
 'Description' => "Description");


    //public $CountryTable =     array('Table' => "Country",    'Key' => "Country", 'Description' => "Country", 'Description2' => "GMTDifferenceHour");
    public $Family =      array('Table' => "Family",    'Key' => "FamilyId", 'Description' => "FamilyShortName", 'Description2' => "ResidentialSuburb");




    public $aDayOfMonthList = array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31');
    public $aMonthList = array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');

    ////////
    // Standard Settings for Australian Telephone/Mobile Numbers



/*
These variables are set for each user in the CheckUser.php script
*/
    public $logged_in;
    public $DebugOn = false;






    public $date;
    public $aMySQLType;
    public $aFieldLookUpTableList;


    //////////////////////////////////////////////////////////////////////////
    // Database variables
    public $dblink;


    protected function ConnectToDatabase($bIgnoreSQLerrors = false){

        if(strpos( $_SERVER["HTTP_HOST"], 'comoj'  ) > 0){
            $this->dbserver = 'mysql5.000webhost.com';
            $this->dbuser= 'a6353064_pactsus';
            $this->dbpass= 'password1';
            $this->dbname = 'a6353064_pacts';
        }

        try{
            $this->dblink = mysql_connect($this->dbserver, $this->dbuser, $this->dbpass) ;
            IF ($this->dblink == NULL){
                throw new Exception("Error Connecting to database");
            } else {
                //echo 'Connected successfully';
                if (!mysql_select_db($this->dbname,$this->dblink) )
                {
                    throw new Exception("Error selecting database : ".$this->dbname);
                } else {

                    // Performing SQL query
                    $query = 'SELECT * FROM '.$this->userstablename;
                    $result = mysql_query($query,$this->dblink);
                    if(!$result)
                    {
                        throw new Exception("Error selecting the user table");

                    }
                }
            }
        }
        catch (Exception $e) {
            // goto 500 page
//            if (!$bIgnoreSQLerrors) $this->error500("Error Message: ".$e->getMessage());
        }


        //echo "End: ConnectToDatabase()<br />";
    }


    function html_header_debug(){
        $buf ="";
        if ($this->DebugOn){
            $buf .= "\n<!-- Session variables \n";
            $buf .= $this->print_ar($_SESSION,true);

            $buf .= "\n-- Server variables \n";
            $buf .= $this->print_ar($_SERVER,TRUE);


            $buf .= "\n-- Cookie variables \n";
            $buf .= $this->print_ar($_COOKIE,TRUE);


            $buf .= "\n-- GET variables \n";
            $buf .= $this->print_ar($_GET,TRUE);


            $buf .= "\n-- POST variables \n";
            $buf .= $this->print_ar($_POST,TRUE);


            $buf .= "\n-- Request variables \n";
            $buf .= $this->print_ar($_REQUEST,TRUE);
            $buf .= "-->\n";

        }
        return $buf;
    }
    function html_header(){
        $buf = "";
        $buf .= $this->html_header_debug();
        //$this->$URLmessage = @$_GET['URLmessage'];

        $buf .= '<?xml version="1.0" encoding="UTF-8"?>';
        $buf .= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'."\n";
        //$buf .= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n";
        $buf .= '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">'."\n";
        $buf .= '<head>'."\n";


        $buf .= '<meta http-equiv="content-type" content="text/html; charset=utf-8" />'."\n";

        // End the prosessing time for the page

        $buf .= '<title>'.$this->SoftwareShortName.': '.$this->SoftwareLongName.' v'.$this->SoftwareVersion.'</title>'."\n";


        $buf .='<link rel="stylesheet" media="screen,projection" type="text/css" href="furniture/css/reset.css" />'."\n";
        $buf .='<link rel="stylesheet" media="screen,projection" type="text/css" href="furniture/css/main.css" />'."\n";
        $buf .='<!--[if IE]><link rel="stylesheet" type="text/css" href="furniture/css/main-ms-IE.css" /><![endif]-->'."\n";
        $buf .='<!--[if lte IE 6]><link rel="stylesheet" type="text/css" href="furniture/css/main-ms-IE6.css" /><![endif]-->'."\n";
        $buf .='<link rel="stylesheet" media="screen,projection" type="text/css" href="furniture/css/style.css" />'."\n";
        $buf .='<link rel="stylesheet" media="print" type="text/css" href="furniture/css/print.css" />'."\n";
        $buf .='<link rel="stylesheet" media="screen,projection" type="text/css" href="furniture/css/phpMyEdit.css" />'."\n";
        /////////////////////////////////
        //  START : JQUERY DROP DOWN CSS/JS

        $buf .='<link rel="stylesheet" href="furniture/css/dropdown_style.css" type="text/css" media="screen, projection"/>'."\n";
        $buf .='<!--[if lte IE 7]><link rel="stylesheet" type="text/css" href="furniture/css/dropdown_style_ie7.css" media="screen" /><![endif]-->'."\n";
        //$buf .='<!--[if lte IE 6]><link rel="stylesheet" type="text/css" href="furniture/css/dropdown_style_ie7.css" media="screen" /><![endif]-->'."\n";

        $buf .='<script type="text/javascript" src="furniture/scripts/jquery-1.3.1.min.js"></script>'."\n";
        $buf .='<script type="text/javascript" src="furniture/scripts/jquery.dropdownPlain.js"></script>'."\n";
        //  END : JQUERY DROP DOWN CSS/JS
        /////////////////////////////////
        $buf .='<script type="text/javascript" src="furniture/scripts/common-functions.js"></script>'."\n";

        //        $buf .='<script type="text/javascript" src="include/scripts.js"></script>'."\n";
        $buf .='</head>'."\n";
        $buf .='<body id="png" class="home">'."\n";
        //// bgcolor="#FFFFFF" text="#000000" leftmargin="2" topmargin="2" marginwidth="2" marginheight="2">'."\n";
        $buf .="<!-- END html_header() -->\n";
        return ($buf);
    }




    function start_header_div($bShowNavUtility=true)
    {
        $buf = "";
        $buf .= "\n<!-- START start_header_div() -->\n";


        $buf .= '<div id="header">';

        //$buf .= "<table class=\"style1\"><tr>td class=\"style1\">";

        $buf .= '<div id="holder1">';
        $buf .= '<div id="brand">';
        $buf .= '<a href="http://mylink">';
        $buf .= '<img src="'.$this->SoftwareLogo.'" alt="PACTS logo"  width="350" />';
        $buf .= '</a></div>'."\n";

        if ($bShowNavUtility){
            $buf .= '<div id="nav-utility">'."\n";
            $buf .= '<ul><li>'.$this->date.'</li>'."\n";


            if (isset($this->_username)){
                $buf .= '<li>User: '.$this->_username.' ('.$this->_group.')- ';
                $buf .= '<a href="index.php?view=Logout">Logout</a></li>'."\n";
                $buf .= '<li><a href="index.php?view=User_ChangePassword&amp;frmUserName='.$this->_username.'&amp;frmUserId='.$_SESSION['UserId'].'" >Change Password</a></li>'."\n";
            }

            //search form
            //            $buf .= '<li>'."\n";
            //            $buf .= '</li>'."\n";
            $buf .= '</ul>'."\n";

            $buf .= '<form id="SearchForm" method="post" action="index.php?view=Find&amp;">'."\n";
            $buf .= '<p>'."\n";
            $buf .= '<input type="text" class="txt" id="searchFld" name="searchstring" title="Search the site" />'."\n";

            $buf .= '<input  type="hidden" name="cbSurname" value="on" />';
            $buf .= '<input  type="hidden" name="cbFirstName" value="on" />';

            //        $buf .= '<input type="text" name="searchstring" size="35" value="todd" class="mediumtxtInput">';


            $buf .= '<input name="search-submit" class="btn" id="search-submit" type="image" value="Search" src="furniture/design/abn_search.gif" alt="Search" />'."\n";
            //$buf .= '</p>'."\n";
            $buf .= '</p>'."\n";
            $buf .= '</form>'."\n";

            $buf .= '</div>'."\n";
            //        $buf .= '<div id="topgrad"></div>'."\n";




        }
        $buf .= '</div>';
        if ($bShowNavUtility){
            $buf .= $this->addNavHorizontal();
        }
        $buf .= "</div><!-- end start_header_div()-->\n";

/*
echo "<pre>";
print_r ($_SESSION);
echo "</pre>";
*/
        $buf .= "<!-- END start_page() -->\n";
        return ($buf);
    }

    function start_page_header(){
        $buf = "";
        $buf .= "<!-- START start_page_header() -->\n";


        if(!is_null($this->URLmessage)) {

            $buf .= '<div id="message">';
            $buf .= trim($this->URLmessage);
            $buf .= '</div>'."\n";
        }

        $buf .= "<!-- END start_page_header() -->\n";
        return $buf;
    }
/*
    function end_page()
    {
        echo '<!-- START end_page() -->'."\n";
        echo '</td></tr></table></div>'."\n";
        echo '<!-- END end_page() -->\n'."\n";
    }
*/
    function div_footer(){
        $buf = "";
        $buf .= '<div id="footer" >'."\n";
        $buf .= '<!-- Do NOT remove the copyright notice -->'."\n";

        $buf .= '<p class="copyright">'."\n";
        $buf .= '<a href="'.$this->SoftwareWebsite.'" class="copyright">'.$this->SoftwareShortName.' : '.$this->SoftwareLongName.'</a>'."\n";
        $buf .= '</p>';
        $buf .= '<p>Copyright &copy; '.$this->SoftwareDate.'</p>'."\n";
        $this->endpageload = $this->utime();
        $run = $this->endpageload - $this->startpageload;
        $buf .= '<p class="smalltxt">Page generated in '.substr($run, 0, 5).' secs.</p>'."\n";
        $buf .= '</div> <!-- end footer DIV -->'."\n";
        return $buf;
    }


    function end_html(){
        $buf = "";
        $buf .= "\n";
        //        echo '</div><!-- end main_content -->'."\n";
        $buf .= $this->div_footer();
        $buf .= '</div> <!-- end page DIV -->'."\n";
        $buf .= '</body>'."\n";
        $buf .= "\n".'</html>';
        return $buf;
    }

    function start_div_main()
    {
        $buf = "";
        $buf .= '<!-- START start_div_main() -->'."\n";;
        $buf .= '<div id="col-top"></div>'."\n";
        $buf .= '<div id="main" class="box">'."\n";
        //        echo '<table class="content1"><tr><td class="content1">'."\n";
        $buf .= '<!-- END start_div_main() -->'."\n";
        return $buf;
    }

    function end_div_main()
    {
        $buf = "";
        $buf .= '<!-- START end_div_main() -->'."\n";
        //        echo"</td></tr></table>";
        $buf .= '</div>'."\n";
        $buf .= '<!-- END end_div_main() -->'."\n";
        $buf .= '<div id="col-bottom"></div>'."\n";
        return $buf;
    }

        /**
         * Add slashes before "'" and "\" characters so a value containing them can
         * be used in a sql comparison.
         *
         * @param   string   the string to slash
         * @param   boolean  whether the string will be used in a 'LIKE' clause
         *                   (it then requires two more escaped sequences) or not
         * @param   boolean  whether to treat cr/lfs as escape-worthy entities
         *                   (converts \n to \\n, \r to \\r)
         *
         * @return  string   the slashed string
         *
         * @access  public
         */
    function PMA_sqlAddslashes($a_string = '', $is_like = FALSE, $crlf = FALSE)
    {
        if ($is_like) {
            $a_string = str_replace('\\', '\\\\\\\\', $a_string);
        } else {
            $a_string = str_replace('\\', '\\\\', $a_string);
        }

        if ($crlf) {
            $a_string = str_replace("\n", '\n', $a_string);
            $a_string = str_replace("\r", '\r', $a_string);
            $a_string = str_replace("\t", '\t', $a_string);
        }

        $a_string = str_replace('\'', '\\\'', $a_string);

        return $a_string;
    } // end of the 'PMA_sqlAddslashes()' function


    function PMA_gpc_extract($array, &$target) {
        // usage        PMA_gpc_extract($HTTP_POST_VARS, $GLOBALS);

        if (!is_array($array)) {
            return FALSE;
        }
        $is_magic_quotes = get_magic_quotes_gpc();
        reset($array);
        while (list($key, $value) = each($array)) {
            if (is_array($value)) {
                $this->PMA_gpc_extract($value, $target[$key]);
            } else if ($is_magic_quotes) {
                $target[$key] = stripslashes($value);
            } else {
                $target[$key] = $value;
            }
        }
        reset($array);
        return TRUE;
    }// PMA_gpc_extract()

    function getFieldDescription($tableName, $ColName)
    {

        $sql =  "SELECT * FROM $this->metadatatablename WHERE TableName like '".$tableName."' and ColumnName like '".$ColName."' ;";
        $fResult = mysql_query($sql,$this->dblink);
        $FLinks = mysql_fetch_array($fResult);
        $returnValue = $FLinks["Description"];

        if($FLinks["DisplayInd"] == 'N') {
            $returnValue = "";
        }

        return $returnValue;
    }

    function myts_date($format, $mytimestamp, $year_start=0, $month_start=5, $day_start=8, $hour_start=11, $min_start=14, $sec_start=17)
    {
        // echo ":: $mytimestamp ::";

        $month  = substr($mytimestamp,$month_start,2);
        $day    = substr($mytimestamp,$day_start,2);
        $year   = substr($mytimestamp,$year_start,4);

        $hour   = substr($mytimestamp,$hour_start,2);
        $min    = substr($mytimestamp,$min_start,2);
        $sec    = substr($mytimestamp,$sec_start,2);

        // echo "h $hour,m $min,s $sec, mth $month,d $day,y $year<br />";

        if($year>1901) {
            $epoch  = mktime($hour,$min,$sec,$month,$day,$year);
            $date   = date ($format, $epoch);
            return $date;
        }
        else {
            return "";
        }
    }



    Function getFmlyNavBar($IndividualId="", $FamilyId="", $bShowViewLink=TRUE, $bShowEditLink=TRUE, $bShowDelLink=TRUE, $DelReturnPage="", $DelReturnArgs="", $bShowAddNewIndvLink=TRUE, $bShowAddNewIndv=TRUE, $leftText="", $bUseTableForFormatting = TRUE){
        //6 text ""
        //7 text ""
        //8 bool
        //9 bool
        //10 text

        if($IndividualId=="") {
            $IndvCode="";
        }else
        {
            $IndvCode='IndividualId='.$IndividualId.'&amp;';

        }

        $strHTML="";



        $strHTML="";
        $strdelimiter = "&nbsp;";

        if ($bUseTableForFormatting){
            $strHTML .= '<tr><td>'."\n";
            $strHTML .= $leftText;
            $strHTML .= '</td>'."\n";
        } else {
            $strHTML .= '<p id="FmlyNavBar">'."\n";
            if (strlen($leftText)>0){
                $strHTML .= $leftText;
                $strHTML .= $strdelimiter."\n";
            }
        }

        if ($bUseTableForFormatting)        {
            $strHTML .=  "\n<td>";
        } else {
            $strHTML .= $strdelimiter."\n";
        }

        if ($bShowViewLink) {
            $strHTML .= '<a class="nbt" href="index.php?view=Fmly_view&amp;'.$IndvCode.'FamilyId='.$FamilyId.'">'."\n";
        }
        $strHTML .= 'View Fmly'."\n";
        if ($bShowViewLink) {
            $strHTML .= '</a>'."\n";
        }

        if ($bUseTableForFormatting)        {
            $strHTML .= '</td>'."\n";
            $strHTML .= '<td>'.$strdelimiter.'</td><td>'."\n";
        } else {
            $strHTML .= $strdelimiter."\n";
        }

        if ($bShowEditLink && $this->getUserCanModify()) {
            $strHTML .= '<a class="nbt" href="index.php?view=Fmly_edit&amp;'.$IndvCode.'FamilyId='.$FamilyId.'">'."\n";
        }
        $strHTML .= 'Edit Fmly'."\n";
        if ($bShowEditLink && $this->getUserCanModify()) {
            $strHTML .= '</a>'."\n";
        }
        if ($bUseTableForFormatting)        {
            $strHTML .= '</td>'."\n";
            $strHTML .= '<td>'.$strdelimiter.'</td><td>'."\n";
        } else {
            $strHTML .= $strdelimiter."\n";
        }
        if ($bShowDelLink && $this->getUserCanDelete()) {
            $strHTML .= '<a class="nbt" href="index.php?view=Fmly_delete&amp;'.$IndvCode.'FamilyId='.$FamilyId;
            if(strlen($DelReturnPage)>0) {
                $strHTML .= '&amp;RedirectLocation='.$DelReturnPage;
            }
            if(strlen($DelReturnArgs)>0) {
                $strHTML .= '&amp;RedirectArgs='.$DelReturnArgs;
            }

            $strHTML .= '" ';
            $strHTML .= 'onclick="cq()">'."\n";
        }
        $strHTML .= 'Delete Fmly'."\n";
        if ($bShowDelLink && $this->getUserCanDelete()) {
            $strHTML .= '</a>'."\n";
        }
        if($bShowAddNewIndv) {
            if ($bUseTableForFormatting)        {
                $strHTML .= '</td>'."\n";
                $strHTML .= '<td>'.$strdelimiter.'</td><td>'."\n";
            } else {
                $strHTML .= $strdelimiter."\n";

            }

            if ($bShowAddNewIndvLink && $this->getUserCanAdd()) {
                $strHTML .= '<a href="index.php?view=Indv_add&amp;AddToFamilyId='.$FamilyId.'">'."\n";
            }
            $strHTML .= 'Add Indv'."\n";
            if ($bShowAddNewIndvLink && $this->getUserCanAdd()) {
                $strHTML .= '</a>'."\n";
            }
        }
        if ($bUseTableForFormatting)        {
            $strHTML .= '</td>'."\n";
        } else {
            $strHTML .= $strdelimiter.'</p>'."\n";
        }
        return $strHTML;
    }



    Function getIndvNavBar($IndividualId, $FamilyId, $bShowView=TRUE, $bShowEdit=TRUE, $bShowDel=TRUE, $DelReturnPage="" ,$DelReturnArgs="", $bShowAddNewIndv=TRUE, $leftText ="", $bUseTableForFormatting = TRUE){

        //6 text ""
        //7 text ""
        //8 bool
        //9 text


        $strHTML="";
        $strdelimiter = "&nbsp;";

        if ($bUseTableForFormatting){
            $strHTML .= '<tr><td>'."\n";
            $strHTML .= $leftText;
            $strHTML .= '</td>'."\n";
        } else {
            $strHTML .= '<p id="IndvNavBar">'."\n";
            if (strlen($leftText)>0){
                $strHTML .= $leftText;
                $strHTML .= $strdelimiter."\n";
            }
        }


        //        $strHTML .= '<td><table cellspacing=0 class="nbt"><tr>";
        if ($bUseTableForFormatting)        {
            $strHTML .=  "\n<td>";
        } else {
            $strHTML .= $strdelimiter."\n";
        }

        if ($bShowView) {
            $strHTML .= '<a href="index.php?view=Indv_view&amp;IndividualId='.$IndividualId.'&amp;FamilyId='.$FamilyId.'">'.'View Indv'.'</a>'."\n";
        } else {
            $strHTML .= 'View Indv'."\n";
        }

        if ($bUseTableForFormatting)        {
            $strHTML .= '</td>'."\n";
            $strHTML .= '<td>'.$strdelimiter.'</td><td>'."\n";
        } else {
            $strHTML .= $strdelimiter."\n";
        }
        if ($bShowEdit && $this->getUserCanModify()) {
            $strHTML .= '<a  href="index.php?view=Indv_edit&amp;IndividualId='.$IndividualId.'&amp;FamilyId='.$FamilyId.'">'.'Edit Indv'.'</a>'."\n";
        } else {
            $strHTML .= 'Edit Indv';

        }
        if ($bUseTableForFormatting)        {
            $strHTML .= '</td>'."\n";
            $strHTML .= '<td>'.$strdelimiter.'</td><td>'."\n";
        } else {
            $strHTML .= $strdelimiter."\n";

        }
        //        $strHTML .= '</td>\n<td class="nbt">";
        if ($bShowDel && $this->getUserCanDelete()) {
            $strHTML .= '<a href="index.php?view=Indv_delete&amp;IndividualId='.$IndividualId.'&amp;FamilyId='.$FamilyId."\n";

            if(strlen($DelReturnPage)>0) {
                $strHTML .= '&amp;RedirectLocation='.$DelReturnPage;
            }
            if(strlen($DelReturnArgs)>0) {
                $strHTML .= '&amp;RedirectArgs='.$DelReturnArgs;
            }
            $strHTML .= '" '.'onclick="cf()">Delete Indv</a>'."\n";
        } else {
            $strHTML .= 'Delete Indv';
        }

        if ($bUseTableForFormatting)        {
            $strHTML .= '</td>'."\n";
            $strHTML .= '<td>'.$strdelimiter.'</td><td>'."\n";
        } else {
            $strHTML .= $strdelimiter."\n";

        }
        if ($bShowAddNewIndv && $this->getUserCanAdd()) {
            $strHTML .= '<a href="index.php?view=Indv_add&amp;AddToFamilyId='.$FamilyId.'">Add Indv</a>'."\n";
        } else {
            $strHTML .= 'Add Indv';
        }

        if ($bUseTableForFormatting)        {
            $strHTML .= '</td>'."\n";
            $strHTML .= '<td>'.$strdelimiter.'</td><td>'."\n";
        } else {
            $strHTML .= $strdelimiter.''."\n";
        }
        if (true) {
            $strHTML .= '<a href="index.php?view=Fmly_view&amp;FamilyId='.$FamilyId.'">View Fmly</a>'."\n";
        } else {
            $strHTML .= 'View Fmly';
        }

        if ($bUseTableForFormatting)        {
            $strHTML .= '</td><td>'."\n";
        } else {
            $strHTML .= $strdelimiter.'</p>'."\n";
        }
        return $strHTML;
    }

    function getFormattedFamilyShortName($FID,$delim=" ", $strFamilyShortName="")
    {
        $CompiledFamilyShortName = "";

        if(strlen($strFamilyShortName)>0) {

        } else {
            $sql = "SELECT `FamilyShortName` FROM ".$this->familytablename." WHERE FamilyId=".$FID.";";
            // echo $sql;
            $fResult = mysql_query($sql,$this->dblink);
            $Flinks = mysql_fetch_array($fResult);
            $strFamilyShortName = $Flinks["FamilyShortName"];
        }

        if(is_null($strFamilyShortName) or strlen(trim($strFamilyShortName)) == 0)
        {
            //  get a compiled name from the individuals in the family
            //  echo "IS NULL or len = 0<p>";

            $sql = "SELECT Surname FROM $this->individualtablename WHERE FamilyId=".$FID." GROUP BY Surname ORDER BY RoleTypeCode DESC, GenderCode DESC;";
            //echo $sql."<p />";
            $CompiledFamilyShortName = "";
            $fResult = mysql_unbuffered_query ($sql,$this->dblink);

            while ($line_indv = mysql_fetch_row($fResult)) {
                $Count = 0;
                foreach ($line_indv as $surname_indv) {
                    if ( !is_null($line_indv[$Count]) ){
                        if (strlen($CompiledFamilyShortName) ==0 ) {
                            $CompiledFamilyShortName = $line_indv[$Count];
                        }else
                        {
                            $CompiledFamilyShortName = $CompiledFamilyShortName.$delim.$line_indv[$Count];
                        }
                    }
                    $Count = $Count + 1;
                }
            }
        }else
        {
            $CompiledFamilyShortName = $strFamilyShortName;
        }

        return $CompiledFamilyShortName;
    } // getFormattedFamilyShortName

    //////////////////////////////////////////////////////////////////////////////////////////////////////

    function getFamilyRoleNameList($FID,$delim,$RoleTypeCode)
    {
        $FamilyRoleNameList = "";

        $sql = "SELECT FirstName FROM ".$this->individualtablename." WHERE FamilyId=".$FID." and RoleTypeCode LIKE '".$RoleTypeCode."';";
        //  echo $sql;
        $FamilyRoleNameList  = "";
        $fResult = mysql_unbuffered_query ($sql,$this->dblink);

        $Count = 0;
        while ($line_indv = mysql_fetch_row($fResult)) {
            foreach ($line_indv as $surname_indv) {
                if ( !is_null($surname_indv) ){

                    if (strlen($FamilyRoleNameList ) ==0 ) {
                        $FamilyRoleNameList  = $surname_indv;
                    }else
                    {
                        $FamilyRoleNameList  = $FamilyRoleNameList .$delim.$surname_indv;
                    }

                }
                $Count = $Count + 1;
            }
        }
        if($Count==0 and strlen($RoleTypeCode)>0 and $RoleTypeCode!="%") {
            $FamilyRoleNameList = $this->getFamilyRoleNameList($FID,$delim,"%");
        }

        if(strlen($FamilyRoleNameList ) ==0 ) {
            $FamilyRoleNameList   = " <b>** NO FAMILY MEMBERS **</b> ";
        }


        return $FamilyRoleNameList ;
    } // getFamilyRoleNameList()

    function getSchoolGrade ($startSchoolYear, $bGrade = TRUE, $bShowYa = FALSE, $bYAIndicator = FALSE){

        // if $bGrade is false, return the description
        $SchoolGrade = "";
        $Grade = "";


        $CurrentYear = date("Y");

        if(!is_null($startSchoolYear) and strlen($startSchoolYear)>0 and ($startSchoolYear <= $CurrentYear))
        {

            $YearDiff = $CurrentYear - $startSchoolYear;
            $sql = "SELECT * FROM $this->educationgradetablename WHERE YearCount=$YearDiff;";
            if ($YearDiff < 0){
                $sql = "SELECT * FROM $this->educationgradetablename WHERE YearCount=$YearDiff AND YearCountOperator='<';";
            }
            if ($YearDiff == 0){
                $sql = "SELECT * FROM $this->educationgradetablename WHERE YearCount=$YearDiff AND YearCountOperator='=';";
            }
            if ($YearDiff > 12){
                $sql = "SELECT * FROM $this->educationgradetablename WHERE YearCount=13 AND YearCountOperator='>';";
            }

            //  echo $sql;

            $fResult = mysql_query($sql,$this->dblink);
            $line_indv = mysql_fetch_array($fResult);
            $Grade  = $line_indv["EducationGrade"];
            $GradeDescription = $line_indv["Description"];


        }
        else
        {
            if ((strlen($startSchoolYear)>0) and ($startSchoolYear > $CurrentYear) and ($startSchoolYear < 2950)){
                $GradeDescription = "Pre";
                $Grade = "Pre";

            }
            // invalid school year
            //  return "Invalid Year";
        }


        if (($bShowYa == TRUE) AND ($bYAIndicator == 'Y')){
            $Grade = "YoungAdult";
        }

        if ($bGrade):
        return $Grade;
        else: return $GradeDescription;
        endif;
    } // getSchoolGrade ()

    //////////////////////////////////////////////////////////////////////////////////////////////////////


    function getNumMonthFromString($strMonth) {
        $mon = 0;
        switch (strtoupper(substr($strMonth,0,3))) {
            case "JAN": $mon='01';
                break;
            case "FEB": $mon='02';
                break;
            case "MAR": $mon='03';
                break;
            case "APR": $mon='04';
                break;
            case "MAY": $mon='05';
                break;
            case "JUN": $mon='06';
                break;
            case "JUL": $mon='07';
                break;
            case "AUG": $mon='08';
                break;
            case "SEP": $mon='09';
                break;
            case "OCT": $mon='10';
                break;
            case "NOV": $mon='11';
                break;
            case "DEC": $mon='12';
                break;
        }
        return $mon;
    }


    function getNumDayOfMonthFromString($strDay) {
        while (strlen($strDay)<2) {
            $strDay ="0".$strDay;
        }
        return $strDay;
    }



    function getOptionList($SelectFieldName, $selectSQL, $selectSQLFieldName, $selectValue){
        //global $JavascriptKeyPress;

        $strHTMLcode = '<!-- getOptionList() -->'."\n";
        $strHTMLcode .= '<select name="'.$SelectFieldName.'"  class="listLookUp" '.$this->JavascriptKeyPress.'>'."\n";
        $strHTMLcode .= '<option value=""';
        if(strlen($selectValue)==0) {
            $strHTMLcode .= ' selected="selected" ';
        }
        $strHTMLcode .= ' />'."\n";

        //echo "<h2>$selectSQL</h2>";

        $result = mysql_query($selectSQL,$this->dblink) or die("Query failed selectSQL: " . mysql_error());
        while($row=mysql_fetch_assoc($result)) {
            //  echo "fld = ".$row[$selectSQLFieldName]."<p>";
            $strHTMLcode .= '<option value="'.$row[$selectSQLFieldName].'"';
            if($selectValue==$row[$selectSQLFieldName]) {
                $strHTMLcode .= ' selected="selected" ';
            }
            $strHTMLcode .= '>'.$row[$selectSQLFieldName].'</option>'."\n";
        };

        $strHTMLcode .= '</select>'."\n";

        return $strHTMLcode;
    }

    //echo getOptionList_old ("abc","Select username from users;","username","colin");
    //echo "<p>";
    //echo getOptionList_old ("abc","Select username from users;","username","joe");
    //exit;


    function getSelectListOfCommonlyUsedSuburbs($Field, $strPreFix,$id,$extraHTML=""){
        $Field = 'CommonlyUsedSuburbs';

        $strHTMLcode = "\n".'<!-- getSelectListOfCommonlyUsedSuburbs() -->'."\n";
        $strHTMLcode .= '<a class="quickselector" href="javascript:;" onmousedown="toggleDiv(\'quickselector_'.$strPreFix.$Field.'\');">Toggle Selector</a>'."\n";
        $strHTMLcode .= '<div class="quickselector" id="quickselector_'.$strPreFix.$Field.'">'."\n";

        //        $strHTMLcode .= '<input onclick="return setFocus(this.form.x'.$id.',2,QuickListItem_'.$strPreFix.$Field.')" type="button" value="&lt;&lt;"'."\n";
        //        $strHTMLcode .= ' title="Move selected item to '.$strPreFix." ".$Field.'" />'."\n";

        $strHTMLcode .= '<input type="button" id="MoveAddrMsgTo_'.$strPreFix.$Field.'" name="MsgTo_'.$strPreFix.$Field.'" value="&lt;&lt;" class="Btn" ';
        $strHTMLcode .= 'title="Move quick list addresses to To field"'."\n".'onclick="return MoveAddrsTo(\''.$strPreFix.'Suburb\',\''.$strPreFix.'Postcode\',\''.$strPreFix.'StateCode\',\'QuickListItem_'.$strPreFix.$Field.'\');" />'."\n";
        //style="font-size: 60%;"
        //        $strHTMLcode .= '<select name="QuickListItem_'.$Field.'" size="5" class="list"   ondblclick="GetID(\'MoveAddrMsgTo\').click()" id="QuickList">';
        $strHTMLcode .= '<select id="QuickListItem_'.$strPreFix.$Field.'" size="6" class="list" ondblclick="return MoveAddrsTo(\''.$strPreFix.'Suburb\',\''.$strPreFix.'Postcode\',\''.$strPreFix.'StateCode\',\'QuickListItem_'.$strPreFix.$Field.'\');">'."\n";
        $strHTMLcode .= '<option selected="selected" value="2745,Glenmore Park,NSW">Glenmore Park (2745)</option>'."\n";
        $strHTMLcode .= '<option value="2750,Penrith,NSW">Penrith (2750)</option>'."\n";
        $strHTMLcode .= '<option value="2750,Penrith South,NSW">Penrith South (2750)</option>'."\n";
        $strHTMLcode .= '<option value="2760,St Marys,NSW">St Marys (2760)</option>'."\n";
        $strHTMLcode .= '<option value="2748,Orchard Hills,NSW">Orchard Hills (2748)</option>'."\n";
        $strHTMLcode .= '<option value="2747,Kingswood,NSW">Kingswood (2747)</option>'."\n";
        $strHTMLcode .= '</select>'."\n"."\n";
        $strHTMLcode .=  '</div>'."\n";
        return $strHTMLcode;
    }

    function getSelectListOfCommonlyUsedStreetTypeCodes($Field, $strPreFix,$id,$extraHTML=""){
        $strHTMLcode = "\n".'<!-- getSelectListOfCommonlyUsedStreetTypeCodes() -->'."\n";

        $strHTMLcode .= '<a class="quickselector" href="javascript:;" onmousedown="toggleDiv(\'quickselector_'.$Field.'\');">Toggle Selector</a>'."\n";
        $strHTMLcode .= '<div class="quickselector" id="quickselector_'.$Field.'">'."\n";

        $strHTMLcode .= '<input onclick="return setFocus(this.form.x'.$id.',2,QuickListItem_'.$Field.')" type="button" value="&lt;&lt;"'."\n";
        $strHTMLcode .= ' title="Move selected item to '.$Field.'" />'."\n";
        $strHTMLcode .= '<select name="QuickListItem_'.$Field.'" size="5" class="list" ondblclick="return setFocus(this.form.x'.$id.',2,QuickListItem_'.$Field.')">'."\n";
        $strHTMLcode .= '<option selected="selected" value="Street">Street</option>'."\n";
        $strHTMLcode .= '<option value="Road">Road</option>'."\n";
        $strHTMLcode .= '<option value="Avenue">Avenue</option>'."\n";
        $strHTMLcode .= '<option value="Circuit">Circuit</option>'."\n";
        $strHTMLcode .= '<option value="Place">Place</option>'."\n";
        $strHTMLcode .= '</select>'."\n"."\n";
        $strHTMLcode .= '</div>';
        return $strHTMLcode;
    }

    function getSelectListOfCommonlyUsedNameTitles($Field, $strPreFix,$id,$extraHTML){
        $Field = 'CommonlyUsedNameTitles';

        $strHTMLcode = "\n".'<!-- getSelectListOfCommonlyUsedNameTitles() -->'."\n";

        $strHTMLcode .= '<a class="quickselector" href="javascript:;" onmousedown="toggleDiv(\'quickselector_'.$Field.'\');">Toggle Selector</a>'."\n";
        $strHTMLcode .= '<div class="quickselector" id="quickselector_'.$Field.'">'."\n";


        $strHTMLcode .= '<input class="quickselectorMover"  onclick="return setFocus(this.form.x'.$id.',2,QuickListItem_'.$Field.')" type="button" value="&lt;&lt;"'."\n";
        $strHTMLcode .= ' title="Move selected item to '.$Field.'" />'."\n";
        //        $strHTMLcode .= $extraHTML."\n";
        $strHTMLcode .= '<select name="QuickListItem_'.$Field.'" size="5" class="list" ondblclick="return setFocus(this.form.x'.$id.',2,QuickListItem_'.$Field.')">'."\n";
        $strHTMLcode .= '<option selected="selected" value="Mr">Mr</option>'."\n";
        $strHTMLcode .= '<option value="Mrs">Mrs</option>'."\n";
        $strHTMLcode .= '<option value="Miss">Miss</option>'."\n";
        $strHTMLcode .= '<option value="Master">Master</option>'."\n";
        $strHTMLcode .= '<option value="Ms">Ms</option>'."\n".'</select>'."\n"."\n";
        $strHTMLcode .= '</div>'."\n";
        return $strHTMLcode;
    }

    function getSelectListOfCommonlyUsedPremiseTypes($Field, $strPreFix,$id,$extraHTML){
        $strHTMLcode = "\n".'<!-- getSelectListOfCommonlyUsedPremiseTypes() -->'."\n";

        $strHTMLcode .= '<a class="quickselector" href="javascript:;" onmousedown="toggleDiv(\'quickselector_'.$Field.'\');">Toggle Selector</a>'."\n";
        $strHTMLcode .= '<div class="quickselector" id="quickselector_'.$Field.'">'."\n";

        $strHTMLcode .= '<input onclick="return setFocus(this.form.x'.$id.',2,QuickListItem_'.$Field.')" type="button" value="&lt;&lt;"'."\n";
        $strHTMLcode .= ' title="Move selected item to '.$Field.'" />'."\n";
        $strHTMLcode .= '<select name="QuickListItem_'.$Field.'" size="5" class="list" ondblclick="return setFocus(this.form.x'.$id.',2,QuickListItem_'.$Field.')" >'."\n";
        $strHTMLcode .= '<option selected="selected" value="Room">Room</option>'."\n";
        $strHTMLcode .= '<option value="Shop">Shop</option>'."\n";
        $strHTMLcode .= '<option value="Site">Site</option>'."\n";
        $strHTMLcode .= '<option value="Townhouse">Townhouse</option>'."\n";
        $strHTMLcode .= '<option value="Unit">Unit</option>'."\n";
        $strHTMLcode .= '</select>'."\n"."\n";
        $strHTMLcode .= '</div>'."\n";
        return $strHTMLcode;
    }


    function getSchoolYearOption($Field, $strPreFix,$extraHTML=""){
        //global $KindergartenAgeCount;
        $strHTMLcode = "\n".'<!-- getSchoolYearOption() -->'."\n";

        $currentyear = (int) Date("Y");
        $PreYear = (int)$currentyear + $this->KindergartenAgeCount;
        //$yeardiff = $currentyear - $KindergartenCommenceYear;
        $PostYear = (int)$currentyear - $this->KindergartenAgeCount;
        $schYear = (int)$currentyear;

        $strHTMLcode .= '<a class="quickselector" href="javascript:;" onmousedown="toggleDiv(\'quickselector_'.$Field.'\');">Toggle Selector</a>'."\n";
        $strHTMLcode .= '<div class="quickselector" id="quickselector_'.$Field.'">'."\n";

        $strHTMLcode .= "\n".'&nbsp;<input type="button" id="MoveAddrMsgTo_'.$Field.'" name="MsgTo_'.$Field.'" value="&lt;&lt;" class="Btn" ';

        $strHTMLcode .= 'title="Move quick list value to KindergartenCommenceYear field" onclick="return setFocusT(this.form.KCY,2,QuickListItem_KindergartenCommenceYear);" />'.$extraHTML."\n";
        //style="font-size: 60%;"
        $strHTMLcode .= '&nbsp;<select name="QuickListItem_'.$Field.'" size="15" class="list"   ondblclick="return setFocusT(this.form.KCY,2,QuickListItem_KindergartenCommenceYear);" id="QuickList">';
        $strHTMLcode .= '<option selected="selected" value="'.$PreYear.'">Pre ('.$PreYear.')</option>'."\n";
        $strHTMLcode .= '<option value="'.$schYear.'">Kind ('.$schYear.')</option>'."\n";
        $schYear = $schYear -1;
        $strHTMLcode .= '<option value="'.$schYear.'">Year1 ('.$schYear.')</option>'."\n";
        $schYear = $schYear -1;
        $strHTMLcode .= '<option value="'.$schYear.'">Year2 ('.$schYear.')</option>'."\n";
        $schYear = $schYear -1;
        $strHTMLcode .= '<option value="'.$schYear.'">Year3 ('.$schYear.')</option>'."\n";
        $schYear = $schYear -1;
        $strHTMLcode .= '<option value="'.$schYear.'">Year4 ('.$schYear.')</option>'."\n";
        $schYear = $schYear -1;
        $strHTMLcode .= '<option value="'.$schYear.'">Year5 ('.$schYear.')</option>'."\n";
        $schYear = $schYear -1;
        $strHTMLcode .= '<option value="'.$schYear.'">Year6 ('.$schYear.')</option>'."\n";
        $schYear = $schYear -1;
        $strHTMLcode .= '<option value="'.$schYear.'">Year7 ('.$schYear.')</option>'."\n";
        $schYear = $schYear -1;
        $strHTMLcode .= '<option value="'.$schYear.'">Year8 ('.$schYear.')</option>'."\n";
        $schYear = $schYear -1;
        $strHTMLcode .= '<option value="'.$schYear.'">Year9 ('.$schYear.')</option>'."\n";
        $schYear = $schYear -1;
        $strHTMLcode .= '<option value="'.$schYear.'">Year10 ('.$schYear.')</option>'."\n";
        $schYear = $schYear -1;
        $strHTMLcode .= '<option value="'.$schYear.'">Year11 ('.$schYear.')</option>'."\n";
        $schYear = $schYear -1;
        $strHTMLcode .= '<option value="'.$schYear.'">Year12 ('.$schYear.')</option>'."\n";
        $schYear = $schYear -1;
        $strHTMLcode .= '<option value="'.$schYear.'">Post ('.$schYear.'-)</option>'."\n";
        $strHTMLcode .= '</select>'."\n";
        $strHTMLcode .= '</div>'."\n";

        return $strHTMLcode;
    }


    Function checkAddressStreetNameNumberConsistency($RecordId, $RecordType, $RecordPrefix, $streetnum, $streetname, $strDelim = "<LI>" ){

        $err = "";
        $PHPSESSID = @$_GET['PHPSESSID'];
        $sqlStart = "Select * from PostcodeSuburbMapping";
        $errState = "";
        $errSuburb = "";
        $errPostcode = "";
        $errSuburbPostcode  = "";
        $err1="";


        if($RecordType=="Family") {
            $RecordTypeShort="Fmly";
        }
        if($RecordType=="Individual") {
            $RecordTypeShort="Indv";
        }

        $fixEditLink = '<a class="edit" href="index.php?view='.$RecordTypeShort.'_edit&amp;'.$RecordType.'Id='.$RecordId.'" rel="external">';
        $fixEditLink .= '<font alt="MANUALLY EDIT THIS RECORD">EDIT</font>';
        $fixEditLink .= '</a>';

        if(strlen($streetname)>0) {
            if(strlen(trim($streetnum))>0) {
                // all is ok
                Return "";
            }
            else {
                // possible error.
                $err1 = "\nMissing ".$RecordPrefix." address Street Number ( '$streetnum' / '$streetname' )";
                return $err1." : ".$fixEditLink;
            }

        } else
        {
            // cannot check since no street name has been given
            Return "";
        }
    }

    Function checkAddressConsistency($RecordId, $RecordType, $RecordPrefix, $state= "", $suburb = "", $postcode = "", $strDelim = "<LI>" ){

        $err = "";
        $PHPSESSID = @$_GET['PHPSESSID'];
        $sqlStart = "Select * from PostcodeSuburbMapping";
        $errState = "";
        $errSuburb = "";
        $errPostcode = "";
        $errSuburbPostcode  = "";
        $err1="";


        if($RecordType=="Family") {
            $RecordTypeShort="Fmly";
        }
        if($RecordType=="Individual") {
            $RecordTypeShort="Indv";
        }

        $fixEditLink = '<a class="edit" href="index.php?view='.$RecordTypeShort.'_edit&amp;'.$RecordType.'Id='.$RecordId.'" rel="external">';
        $fixEditLink .= '<font  alt="MANUALLY EDIT THIS RECORD">EDIT</font>';
        $fixEditLink .= '</a>';

        $fixLink="\n</UL>\n<table border=1 cellpadding=0 cellspacing=0>\n<tr>\n<td>\n<table>";
        $fixLink.="\n<tr><td>\n";
        $fixLink.="<b><center><font class=\"UpdateLinkTitle\">CLICK LINK TO FIX AUTOMATICALLY</font></center></b>";
        $fixLink.="\n</td></td>\n";


        $sql = $sqlStart." WHERE StateCode = '".$state."' and ";
        $sql = $sql." Postcode = '$postcode' and ";
        $sql = $sql." Suburb = '$suburb';";
        // echo $sql."<p>";
        $result = mysql_query($sql,$this->dblink) or die("Query failed : " . mysql_error());

        if (mysql_num_rows($result)>0) {
            //
            // It exists, return blank
            //

            return "";
        } else
        {
            //
            // Problem with combination of 3 details
            //
            //  $errState = trim(checkAddressConsistency($RecordId, $RecordType, $RecordPrefix,$state, "", "" ));
            //  $errSuburb = trim(checkAddressConsistency($RecordId, $RecordType, $RecordPrefix,"", $suburb, "" ));
            //  $errPostcode = trim(checkAddressConsistency($RecordId, $RecordType, $RecordPrefix,"", "", $postcode ));

            if (strlen($postcode)>0)
            {
                //   echo "At: Postcode check<p>";
                $sql = $sqlStart." WHERE Postcode = '".$postcode."';";
                //   echo $sql."<p>";
                $result = mysql_query($sql,$this->dblink) or die("Query failed : " . mysql_error());
                if (mysql_num_rows($result)>0) {
                    $errPostcode = "";
                } else
                {
                    $errPostcode = "<b>Invalid Postcode </b>('$postcode').   ** SHOW Postcodes for suburb ** ";
                }
            }

            if (strlen($state)>0)
            {
                //   echo "At: State check<p>";
                $sql = $sqlStart." WHERE StateCode = '".$state."';";
                //   echo $sql."<p>";
                $result = mysql_query($sql,$this->dblink) or die("Query failed : " . mysql_error());
                if (mysql_num_rows($result)>0) {
                    $errState = "";
                } else
                {
                    $errState = "<b>Invalid State</b> ( '$state' ). ** SHOW State lists ** " ;
                }
            }

            if (strlen($suburb)>0)
            {
                //   echo "At: Suburb check<p>";
                $sql = $sqlStart." WHERE Suburb = '".$suburb."';";
                //   echo $sql."<p>";
                $result = mysql_query($sql,$this->dblink) or die("Query failed : " . mysql_error());
                if (mysql_num_rows($result)>0) {
                    $errSuburb = "";
                } else
                {
                    $errSuburb =  "<b>Invalid Suburb </b>( '$suburb' ). ** SHOW suburbs for Postcode ** ";
                }
            }

            //  echo "ERRORS: errState=$errState  errPostcode=$errPostcode  errSuburb=$errSuburb<br />";

            if(strlen($errSuburb)==0) {
                //  If SUBURB IS VALID THEN
                // check Postcode/Suburb combination
                $sql = $sqlStart." WHERE Suburb = '".$suburb."' and Postcode = '".$postcode."';";
                $result = mysql_query($sql,$this->dblink) or die("Query failed : " . mysql_error());
                if (mysql_num_rows($result)>0) {
                    $errSuburbPostcode  = "";
                } else
                {
                    $errSuburbPostcode  =  "<b>Invalid SUBURB / POSTCODE</b>( '$suburb' / '$postcode')";
                }
                if(strlen($errSuburbPostcode)==0) {
                    //    echo "<h1>POSTCODE IS VALID FOR SUBURB - FIXING STATE</h1>";
                    //   IF POSTCODE IS VALID FOR SUBURB
                    //**************//
                    //      FIX STATE
                    //**************//

                    $sql = $sqlStart." WHERE Suburb = '".$suburb."' and Postcode = '".$postcode."';";
                    $result = mysql_query($sql,$this->dblink) or die("Query failed : " . mysql_error());
                    while($row=mysql_fetch_assoc($result)) {
                        $fixSQL = htmlentities(urlencode('UPDATE '.$RecordType.' SET '.$RecordPrefix.'StateCode = "'.$row['StateCode'].'" WHERE '.$RecordType.'Id = '.$RecordId.';'));
                        $fixLink .= "<tr><td>\n";
                        $fixLink .= '<a href="javascript:openUpdateSql(\''.$fixSQL.'\', \''.$PHPSESSID.'\')" class="UpdateLink">';
                        $fixLink .= "Update State to '".$row['StateCode']."'</a>\n";
                        $fixLink = $fixLink."\n";
                        $fixLink .= "</td></tr>\n";
                        //****************************************************************************************************//
                    } // END WHILE

                    $fixLink .= "\n</table>\n</td></tr></table>\n<UL>\n";
                    $err1 .= "\nInvalid ".$RecordPrefix." address State for Postcode/Suburb ( '$postcode' / '$suburb' )";

                    return getAddressError($err, $err1." : ".$fixEditLink." ".$fixLink,"",$strDelim);
                } else {
                    //   ELSE
                    $sql = $sqlStart." WHERE Suburb = '".$suburb."' and StateCode = '".$state."';";
                    $result = mysql_query($sql,$this->dblink) or die("Query failed : " . mysql_error());
                    if (mysql_num_rows($result)>0) {
                        $errStateSuburb  = "";
                    } else
                    {
                        $errStateSuburb =  "STATE / Suburb ( 'state' / '$suburb' ) is INVALID";
                    }
                    if(strlen($errStateSuburb )==0) {
                        //     echo "STATE IS VALID FOR SUBURB - SUGGUESTING POSTCODE";
                        //    IF STATE IS VALID FOR SUBURB
                        //**************//
                        //     SUGGUEST POSTCODE
                        //**************//
                        //96225652
                        //****************************************************************************************************//
                        // find correct postcode and for suburb/state
                        $sql = $sqlStart." WHERE Suburb = '".$suburb."' and StateCode = '".$state."';";
                        $result = mysql_query($sql,$this->dblink) or die("Query failed : " . mysql_error());
                        $fixSQL="";
                        while($row=mysql_fetch_assoc($result)) {
                            $fixSQL = htmlentities(urlencode('UPDATE '.$RecordType.' SET '.$RecordPrefix.'Postcode = "'.$row['Postcode'].'" WHERE '.$RecordType.'Id = '.$RecordId.';'));
                            $fixLink .= "<tr><td>\n";
                            $fixLink .= '<a href="javascript:openUpdateSql(\''.$fixSQL.'\', \''.$PHPSESSID.'\')" class="UpdateLink">';
                            $fixLink .= "Update Postcode to '".$row['Postcode']."' and State to '".$row['StateCode']."'</a>\n";
                            $fixLink = $fixLink."\n";
                            $fixLink .= "</td></tr>\n";
                            //****************************************************************************************************//
                        } // END WHILE
                        $fixLink .= "\n</table>\n</td></tr></table>\n<UL>\n";
                        $err1 .= "\n<b>Invalid ".$RecordPrefix." address Postcode</b> for State/Suburb ( '$state' / '$suburb' )";

                        return getAddressError($err, $err1." : ".$fixEditLink." ".$fixLink,"",$strDelim);
                        //     return getAddressError($err, $err1." : ".$fixLink,"",$strDelim);

                    } else {
                        //    ELSE
                        //     echo "STATE AND POSTCODE ARE INVALID FOR SUBURB - SUGGUESTING POSTCODE/STATE";
                        // state and postcode is invalid for suburb
                        //**************//
                        //     SUGGUEST LIST OF POSTCODES/STATES FOR given SUBURB
                        //****************************************************************************************************//
                        // find correct postcode and for suburb
                        $sql = $sqlStart." WHERE Suburb = '".$suburb."';";
                        $result = mysql_query($sql,$this->dblink) or die("Query failed : " . mysql_error());
                        $fixSQL=="";
                        //     echo "<p>";
                        while($row=mysql_fetch_assoc($result)) {
                            $fixSQL = htmlentities(urlencode('UPDATE '.$RecordType.' SET '.$RecordPrefix.'StateCode = "'.$row['StateCode'].'", '.$RecordPrefix.'Postcode = "'.$row['Postcode'].'" WHERE '.$RecordType.'Id = '.$RecordId.';'));
                            $fixLink .= "<tr><td>\n";
                            $fixLink .= '<a href="javascript:openUpdateSql(\''.$fixSQL.'\', \''.$PHPSESSID.'\')" class="UpdateLink">';
                            $fixLink .= "Update Postcode to '".$row['Postcode']."' and State to '".$row['StateCode']."'</a>\n";
                            $fixLink = $fixLink."\n";
                            $fixLink .= "</td></tr>\n";
                        };
                        $fixLink .= "\n</table>\n</td></tr></table>\n<UL>\n";
                        print "srlen = ".strlen($fixSQL);
                        if ($fixSQL==""){ $fixLink = "";}

                        $err1 .= "\n<b>Invalid ".$RecordPrefix." address</b> combination of State/Suburb ( '$state' / '$suburb' )";
                        return getAddressError($err, $err1." : ".$fixEditLink." ".$fixLink,"",$strDelim);
                        //****************************************************************************************************//
                        //**************//
                        //    END IF
                    } //end if
                    //   END IF
                } //end if
                //
            } else {
                //  ELSE
                // SUBURB IS NOT VALID
                if(strlen($errPostcode)==0) {
                    //   IF POSTCODE IS VALID
                    //**************//
                    //     SUGGEST SUBURB/STATE for given POSTCODE
                    //**************//
                    // find correct suburb/state for postcode
                    $sql = $sqlStart." WHERE Postcode = '".$postcode."';";
                    $result = mysql_query($sql,$this->dblink) or die("Query failed : " . mysql_error());

                    while($row=mysql_fetch_assoc($result)) {
                        //      echo"<h2>Update Suburb to '".$row['Suburb']."' and State to '".$row['StateCode']."'</h1>\n";
                        $fixSQL = htmlentities(urlencode('UPDATE '.$RecordType.' SET '.$RecordPrefix.'StateCode = "'.$row['StateCode'].'", '.$RecordPrefix.'Suburb = "'.$row['Suburb'].'" WHERE '.$RecordType.'Id = '.$RecordId.';'));
                        $fixLink .= "<tr><td>\n";
                        $fixLink .= '<a href="javascript:openUpdateSql(\''.$fixSQL.'\', \''.$PHPSESSID.'\')" class="UpdateLink">';
                        $fixLink .= "Update Suburb to '".$row['Suburb']."' and State to '".$row['StateCode']."'</a>\n";
                        $fixLink = $fixLink."\n";
                        $fixLink .= "</td></tr>\n";
                    };
                    $fixLink .= "\n</table>\n</td></tr></table>\n<UL>\n";
                    $err1 .= "\n<b>Invalid ".$RecordPrefix." address </b>combination of State/Suburb ( '$state' / '$suburb' )";
                    Return getAddressError($err, $err1." : ".$fixEditLink." ".$fixLink,"",$strDelim);

                    //   ELSE
                } else {
                    //    echo "<h1>** ALL DETAILS INCORRECT : EDIT** </h1><p>";
                    $err1 = "\n<b>Invalid ".$RecordPrefix." address</b> combination of State/Suburb/Postcode ( '$state' / '$suburb' / '$postcode' )";
                    Return getAddressError($err, $err1." : ".$fixEditLink,"",$strDelim);
                    //**************//
                    //     CANNOT SUGGUEST. EDIT
                    //**************//
                    //   END IF
                } //end if
                //  END IF
            } //end else
        }//end else
    }//end function checkAddressConsistency()


    Function checkAgeRangeBirthdateConsistency( $RecordId, $RecordType, $RecordPrefix, $AgeRange= "", $BirthDate="", $strDelim = "<LI>" ){

        $PHPSESSID = @$_GET['PHPSESSID'];

        $err = "";
        if($RecordType=="Family") {
            $RecordTypeShort="Fmly";
        }
        if($RecordType=="Individual") {
            $RecordTypeShort="Indv";
        }

        $fixEditLink = '<a class="edit" href="index.php?view='.$RecordTypeShort.'_edit&amp;'.$RecordType.'Id='.$RecordId.'" rel="external">';
        $fixEditLink .= '<font  alt="MANUALLY EDIT THIS RECORD">EDIT</font>';
        $fixEditLink .= '</a>';

        // if BirthDate is valid, check AgeRange
        // format CCYY-MM-DD

        // $mydate = myts_date("d-F-Y",$BirthDate,0,5,8);
        $Day = myts_date("d",$BirthDate,0,5,8);
        $Month = myts_date("m",$BirthDate,0,5,8);
        $Year = myts_date("Y",$BirthDate,0,5,8);
        // echo "BD: $BirthDate : $Day : $Month : $Year<p>";
        if($Year>0) {
            If ($Year < 100) $iYear = 1900 + $Year;
            $baseyear = date("Y") - $Year - 1;
            If ($Month < date("m") OR ($Month == date("m") AND $Day <= date("d"))) $baseyear++; // had birthday
            // echo "<H2>AGE = $baseyear</H2><p>";

            if($baseyear>=0) {
                $sql = "Select * From AgeRange WHERE LowerAgeLimit <= $baseyear and UpperAgeLimit >= $baseyear;";
                //   echo $sql."<p>";
                $result = mysql_query($sql,$this->dblink) or die("Query failed : " . mysql_error());

                if (mysql_num_rows($result)>0) {
                    $row=mysql_fetch_array($result);
                    //     echo "<H1>Age Range = ".$row['AgeRange']."</H1><p>";
                    //    echo "got rows  '$AgeRange'<p>";
                    if(strlen($AgeRange)==0 ) {

                        $fixSQL = urlencode('UPDATE '.$RecordType.' SET AgeRange = "'.$row['AgeRange'].'" WHERE '.$RecordType.'Id = '.$RecordId.';');
                        $fixLink = '<a class="fix" href="javascript:openUpdateSql(\''.$fixSQL.'\', \''.$PHPSESSID.'\')">';
                        $fixLink .= '<font  alt="FIX THIS RECORD">FIX</font>';
                        $fixLink .= '</a>';


                        return getAddressError($err, "UPDATE <b>AgeRange</b> field to reflect AgeRange ( '".$row['AgeRange']."' ) from birthdate : ".$fixLink,"",$strDelim);
                    }
                    if((strlen($AgeRange)>0 and $AgeRange!=$row['AgeRange'])) {
                        $fixSQL = urlencode('UPDATE '.$RecordType.' SET AgeRange = "'.$row['AgeRange'].'" WHERE '.$RecordType.'Id = '.$RecordId.';');
                        $fixLink = '<a class="fix" href="javascript:openUpdateSql(\''.$fixSQL.'\', \''.$PHPSESSID.'\')">';
                        $fixLink .= '<font  alt="FIX THIS RECORD">FIX</font>';
                        $fixLink .= '</a>';

                        return getAddressError($err, "<b>Incorrect AgeRange</b> field ( '".$row['AgeRange']."' ) according to birthdate : ".$fixLink,"",$strDelim);
                    }
                }
            } else {
                return "ERROR - <b>Invalid year</b> In BirthDate ( ' $Year ' ) $fixEditLink <p>";
            } // end else
        } // end if
        Return $err;
    } // end checkAgeRangeBirthdateConsistency()



    Function checkEmailConsistency( $RecordId, $RecordType, $RecordPrefix, $email= "", $strDelim = "<LI>" ){
        $err = "";
        if($RecordType=="Family") {
            $RecordTypeShort="Fmly";
        }
        if($RecordType=="Individual") {
            $RecordTypeShort="Indv";
        }

        $fixEditLink = '<a class="edit" href="index.php?view='.$RecordTypeShort.'_edit&amp;'.$RecordType.'Id='.$RecordId.'" rel="external">';
        $fixEditLink .= '<font alt="MANUALLY EDIT THIS RECORD">EDIT</font>';
        $fixEditLink .= '</a>';
        if(strlen(trim($email))>0) {
            $pos = strpos($email, "@");
            $domain = strstr($email, '@');
            $username = substr($email, 0, $pos);

            // echo "domain = ".$domain."<p>";
            // echo "username = ".$username."<p>";

            if(strlen($domain)>0 and strpos($domain, '@',1)==TRUE) {
                $err = getAddressError($err, "<b>Invalid ".$RecordPrefix." email address format</b> - @ occurs more than once ( '$email' ) ".$fixEditLink ,"",$strDelim);
            }

            if(strlen($username)==0) {
                $err = getAddressError($err, "<b>Invalid ".$RecordPrefix." email address format</b> - username is not specified (i.e username@domain.com) ( '$email' ) ".$fixEditLink ,"",$strDelim);
            }
        } // end if
        Return $err;
    } // end checkEmailConsistency()



    Function checkPhoneNumberConsistency( $RecordId, $RecordType, $RecordPrefix, $CountryCode= "", $STD = "", $NonMobPhnumber = "", $MobPhnumber = "", $strDelim = "<LI>" ){
        //echo "checkPhoneNumberConsistency($RecordId, $RecordType, $RecordPrefix, $CountryCode , $STD , $NonMobPhnumber , $MobPhnumber , $strDelim <p>\n";

        global $intDefaultInternationalTelephoneCode ;
        global $intDefaultSTDLength ;
        global $bNoLeadingZeroInSTD ;
        global $intDefaultNonMobileTelephoneNumberLength ;
        global $intDefaultMobileTelephoneNumberLength;

        $err = "";
        $PHPSESSID = @$_GET['PHPSESSID'];

        if($RecordType=="Family") {
            $RecordTypeShort="Fmly";
        }
        if($RecordType=="Individual") {
            $RecordTypeShort="Indv";
        }



        $fixEditLink = '<a class="edit" href="index.php?view='.$RecordTypeShort.'_edit&amp;'.$RecordType.'Id='.$RecordId.'" rel="external">';
        $fixEditLink .= '<font alt="MANUALLY EDIT THIS RECORD">EDIT</font>';
        $fixEditLink .= '</a>';

        if(strlen($CountryCode)>0 and $CountryCode=="".$intDefaultInternationalTelephoneCode) {
            // got Australian
            //  echo "got Aussue<p>";

            if(strlen($NonMobPhnumber)>0) {
                //  echo "Non Mobile Number, checking STD $STD<p>";
                // check STD
                if(strlen($STD)>0 AND substr ( $STD, 0 ,1)=="0" AND $bNoLeadingZeroInSTD==TRUE) {

                    $fixSQL = urlencode('UPDATE '.$RecordType.' SET '.$RecordPrefix.'StdCode = "'.substr($STD, 1).'" WHERE '.$RecordType.'Id = '.$RecordId.';');
                    $fixLink = '<a class="fix" href="javascript:openUpdateSql(\''.$fixSQL.'\', \''.$PHPSESSID.'\')">';
                    $fixLink .= '<font alt="FIX THIS RECORD">FIX</font>';
                    $fixLink .= '</a>';

                    $err = getAddressError($err, "<b>Invalid ".$RecordPrefix." STD</b> leading zeros ( '$STD' ) : ".$fixLink,"",$strDelim);
                } else {
                    if(strlen($STD)>0 AND substr ( $STD, 0 ,1)!="0" AND $bNoLeadingZeroInSTD==FALSE) {
                        $err = getAddressError($err, "Missing ".$RecordPrefix." STD leading zeros ( '$STD' )","",$strDelim);
                    }
                    if(strlen($STD)!= $intDefaultSTDLength) {
                        $fixLink = '<a class="edit" href="index.php?view='.$RecordTypeShort.'_edit&amp;'.$RecordType.'Id='.$RecordId.'" rel="external">';
                        $fixLink .= '<font alt="MANUALLY EDIT THIS RECORD">EDIT</font>';
                        $fixLink .= '</a>';
                        $err = getAddressError($err, "<b>Invalid ".$RecordPrefix." STD</b> length ( '$STD' - length should be $intDefaultSTDLength ) ".$fixLink ,"",$strDelim);
                    }
                }

                // check NonMob Number
                //echo "Checking lenghth of NonMobPhoneNum<br />";
                if(strlen($NonMobPhnumber)>0 AND strlen($NonMobPhnumber)!= $intDefaultNonMobileTelephoneNumberLength) {
                    //    echo "Invalid NonMobPhnumber length<br />";
                    $err = getAddressError($err, "<b>Invalid ".$RecordPrefix." number length</b> ( '$NonMobPhnumber' - length should be $intDefaultNonMobileTelephoneNumberLength numbers ) ".$fixEditLink,"",$strDelim);
                }
            }
            // check Mobile Number
            if(strlen($MobPhnumber)>0 AND strlen($MobPhnumber)!= $intDefaultMobileTelephoneNumberLength) {
                $fixLink = '<a class="edit" href="index.php?view='.$RecordTypeShort.'_edit&amp;'.$RecordType.'Id='.$RecordId.'" rel="external">';
                $fixLink .= '<font alt="MANUALLY EDIT THIS RECORD">EDIT</font>';
                $fixLink .= '</a>';

                $err = getAddressError($err, "Invalid <b>mobile phone number length</b> ( '$MobPhnumber' - length should be $intDefaultMobileTelephoneNumberLength ) ".$fixLink,"",$strDelim);
            }
        } else {
            if(strlen($CountryCode)==0 and strlen($NonMobPhnumber)>0) {

                $fixSQL = htmlentities(urlencode('UPDATE '.$RecordType.' SET '.$RecordPrefix.'InternationalCode = '.$intDefaultInternationalTelephoneCode.' WHERE '.$RecordType.'Id = '.$RecordId.';'));
                $fixLink = '<a class="fix" href="javascript:openUpdateSql(\''.$fixSQL.'\', \''.$PHPSESSID.'\')">';
                $fixLink .= '<font alt="FIX THIS RECORD">FIX</font>';
                $fixLink .= '</a>';
                $err = getAddressError($err, "Missing <b>".$RecordPrefix." International Code</b> ( Default is '$intDefaultInternationalTelephoneCode' ) ".$fixLink ,"", $strDelim);
            }
            if(strlen($CountryCode)>0 and strlen($NonMobPhnumber)>0) {
                $fixSQL = htmlentities(urlencode('UPDATE '.$RecordType.' SET '.$RecordPrefix.'InternationalCode = '.$intDefaultInternationalTelephoneCode.' WHERE '.$RecordType.'Id = '.$RecordId.';'));
                $fixLink = '<a class="fix" href="javascript:openUpdateSql(\''.$fixSQL.'\', \''.$PHPSESSID.'\')">';
                $fixLink .= '<font alt="FIX THIS RECORD">FIX</font>';
                $fixLink .= '</a>';
                $err = getAddressError($err, "<b>Non Australian ".$RecordPrefix." International Code</b> ( Default is '$intDefaultInternationalTelephoneCode' ) ".$fixLink ,"",$strDelim);

            }
        }
        // echo "returnung : $err<p>";
        Return trim($err);
    }



    function getLookupTableHTML($LookupTableName,$formItemName,$defaultValue="",$id="") {
        //global $aFieldLookUpTableList;
        global $JavascriptKeyPress;

        $LookupTableHTML = "";

        if($this->aFieldLookUpTableList[$LookupTableName]) {

            $sql =  "SELECT * FROM `".$this->aFieldLookUpTableList[$LookupTableName]['Table']."` ORDER BY  ".$this->aFieldLookUpTableList[$LookupTableName]['Description'].";";

            if($this->aFieldLookUpTableList[$LookupTableName]['Table']=="AgeRange") {
                $sql =  "SELECT * FROM `".$this->aFieldLookUpTableList[$LookupTableName]['Table']."` ORDER BY OrderNum;";
            }

            //echo "<pre>";
            //echo $sql;
            //echo "</pre>";

            $result = mysql_query($sql,$this->dblink);


            $LookupTableHTML .= '<select class="listLookUp" name="'.$formItemName.'" id="x'.$id.'" '.$JavascriptKeyPress.'>'."\n";

            // insert blank entry
            $selected = "";
            if($defaultValue == "" or is_null($defaultValue)) {
                $selected = ' selected="selected" ';

            }
            $LookupTableHTML .= '<option value="" '.$selected.' />'."\n";


            while($row = mysql_fetch_assoc($result)) {
                $selected = "";
                if(strtoupper($row[$this->aFieldLookUpTableList[$LookupTableName]['Key']]) == strtoupper($defaultValue)) {
                    $selected = ' selected="selected" ';
                }

                $LookupTableHTML .= "\t";
                $LookupTableHTML .= '<option value="'.htmlspecialchars($row[$this->aFieldLookUpTableList[$LookupTableName]['Key']]).'" '.$selected.'>';
                if(strlen($row[$this->aFieldLookUpTableList[$LookupTableName]['Description']])>0)
                {
                    $LookupTableHTML .= ''.htmlspecialchars($row[$this->aFieldLookUpTableList[$LookupTableName]['Description']]).'';
                }

                if(strpos($formItemName,"FamilyId") > 0) {
                    $HeadOfFamily =  htmlspecialchars($row['ResidentialStreetNum']." ".$row['ResidentialStreetName']." ".$row['ResidentialStreetTypeCode']);

                    //   $HeadOfFamily =  getFamilyRoleNameList($row['FamilyId']," + ","Head Of Family");
                    if(strlen($HeadOfFamily)>0) {
                        $LookupTableHTML .= ",(".$HeadOfFamily.")";
                    } else {
                        $LookupTableHTML .= " - ,";

                    }
                }


                if(@strlen($row[$this->aFieldLookUpTableList[$LookupTableName]['Description2']])>0)
                {
                    $LookupTableHTML .= ', '.htmlspecialchars($row[$this->aFieldLookUpTableList[$LookupTableName]['Description2']]).'';
                }
                $LookupTableHTML .= '</option>'."\n";
            }
            $LookupTableHTML .= "</select>"."\n";
            mysql_free_result($result);
        }else
        {
            $LookupTableHTML = "";
        }
        return $LookupTableHTML;
    }

    function getDayOfMonthHTML($objName, $selectedItem) {

        $strHTML ="\n";
        $strHTML .='<select name="'.$objName.'">';
        $strHTML .="\n\t";
        $bSelected = FALSE;
        if(is_null($selectedItem) or !strlen($selectedItem)>0) {

            $strHTML .='<option value="" selected="selected"></option>';
            $strHTML .="\n\t";
            $bSelected = TRUE;
        } else
        {
            $strHTML .='<option value=""></option>';
            $strHTML .="\n\t";
        }
        // echo "is arrary".is_array($aDayOfMonthList)."<br />";
        foreach ($this->aDayOfMonthList as $DOM) {
            if(trim($DOM) == trim($selectedItem) AND $bSelected == FALSE) {
                $strHTML .='<option value="'.$DOM.'" selected="selected">'.$DOM.'</option>';
                $strHTML .="\n\t";
                $bSelected = TRUE;
            } else {
                $strHTML .='<option value="'.$DOM.'">'.$DOM.'</option>';
                $strHTML .="\n\t";
            }
        }
        $strHTML .="\n";
        $strHTML .='</select>';
        $strHTML .="\n";
        return $strHTML;
    }

    function getMonthHTML($objName, $selectedItem) {

        $strHTML ="\n";
        $strHTML .='<select name="'.$objName.'">';
        $strHTML .="\n\t";
        $bSelected = FALSE;
        if(is_null($selectedItem) or !strlen($selectedItem)>0) {


            $strHTML .='<option value="" selected="selected"></option>';
            $strHTML .="\n\t";
            $bSelected = TRUE;
        } else
        {
            $strHTML .='<option value=""></option>';
            $strHTML .="\n\t";
        }
        // echo "is arrary".is_array($aDayOfMonthList)."<br />";
        foreach ($this->aMonthList as $Month) {
            if(trim($Month) == trim($selectedItem) AND $bSelected == FALSE) {
                $strHTML .='<option value="'.$Month.'" selected="selected">'.$Month.'</option>';
                $strHTML .="\n\t";
                $bSelected = TRUE;
            } else {
                $strHTML .='<option value="'.$Month.'">'.$Month.'</option>';
                $strHTML .="\n\t";
            }
        }
        $strHTML .="\n";
        $strHTML .='</select>';
        $strHTML .="\n";
        return $strHTML;
    }

    function addNavHorizontal(){
        $buf = '';


        $buf .= '<div id="dropdownmenu">'."\n";
        //HOME
        $buf .= '<ul class="dropdown">'."\n";
        $buf .= '<li><a href="index.php?view=Home" >Home</a></li>'."\n";
        //INDIVIDUAL
        $buf .= '<li><a href="#" >Individual</a>'."\n";
        $buf .= '<ul class="sub_menu">'."\n";
        $buf .= '<li><a href="index.php?view=Indv_az_index" >View</a>'."\n";
        $buf .= '<ul class="menu_az_col1">'."\n";

        $AZarray = array("all","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z");
        foreach ($AZarray as $i => $value) {
            $cur = $AZarray[$i];
            if($cur=="n"){
                //break
                $buf .=  '</ul>'."\n";
                $buf .= '<ul class="menu_az_col2">'."\n";
            }
            $buf .=  '<li>';
            $buf .= '<a href="index.php?view=Indv_az_list&amp;alphabet='.$cur.'">'.strtoupper($cur).'</a>';
            $buf .=  '</li>'."\n";
            unset($AZarray[$i]);
        }
        $buf .= '</ul>'."\n";
        $buf .= '</li>'."\n";

        if ($this->getUserCanAdd()){
            $buf .= '<li><a href="index.php?view=Indv_add" >Add</a></li>'."\n";
        }
        $buf .= '</ul>'."\n";
        $buf .= '</li>'."\n";
        $buf .= '<li><a href="#" >Family</a>'."\n";
        $buf .= '<ul class="sub_menu">'."\n";
        $buf .= '<li><a href="index.php?view=Fmly_az_index" >View</a>'."\n";
        $buf .= '<ul class="menu_az_col1">'."\n";

        $AZarray = array("all","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z");
        foreach ($AZarray as $i => $value) {
            $cur = $AZarray[$i];
            if($cur=="n"){
                //break
                $buf .=  '</ul>'."\n";
                $buf .= '<ul class="menu_az_col2">'."\n";
            }

            $buf .=  '<li>';
            $buf .= '<a href="index.php?view=Fmly_az_list&amp;alphabet='.$cur.'">'.strtoupper($cur).'</a>';
            $buf .=  '</li>'."\n";
            unset($AZarray[$i]);
        }
        $buf .='</ul>'."\n";
        $buf .= '</li>'."\n";
        if ($this->getUserCanAdd()){
            $buf .= '<li><a href="index.php?view=Fmly_add" >Add</a></li>';
        }
        $buf .= '</ul>'."\n";
        $buf .= '</li>'."\n";

        $buf .= '<li><a href="#" >Reports</a>'."\n";
        $buf .= '<ul>'."\n";
        $buf .= '<li><a href="index.php?view=Reports_overview" >Overview</a>'."\n";
        //turn off for now...
        if (false){
            $buf .= '<ul>'."\n";
            //build dynamic list of Report pages
            $dir = "_content/_reports";
            $count =0;
            $opened_file = opendir($dir);
            while ( $file = readdir($opened_file) ) {
                if ( $file != "." && $file != ".." && substr($file, strlen($file)-4, 4) == ".php") {
                    $buf .= '<li><a href="index.php?view=Reports_filter&amp;ReportToFilter='.substr($file,0, strlen($file)-4).'" >'.substr($file,0, strlen($file)-4).'</a></li>'."\n";
                }
            }



            $buf .= '</ul>'."\n";
        }            $buf .= '</li>'."\n";
        $buf .= '</ul>'."\n";
        $buf .= '</li>'."\n";

        if ($this->getUserIsAdmin()){
            $buf .= '<li><a href="#" >Admin</a>'."\n";
            $buf .= '<ul class="sub_menu">'."\n";
            $buf .= '<li><a href="index.php?view=RefData_All">Reference Data</a>'."\n";

            //build dynamic list of Reference data pages
            $buf .= '<ul class="RefDataFlyOut">'."\n";
            $base_page_name = "index.php?view=RefData_All";
            $dir = "_content/_ReferenceData";
            $count =0;
            $opened_file = opendir($dir);
            while ( $file = readdir($opened_file) ) {
                if ( $file != "." && $file != ".." && substr($file, strlen($file)-4, 4) == ".php") {
                    if (strpos(" ".$file, "phpMyEdit")>0){
                        continue;
                    }
                    //add to array.
                    $fileList[] = substr($file,0, strlen($file)-4);
                }
            }
            sort($fileList);
            foreach ($fileList as $filename) {
                $buf .= '<li><a href="'.$base_page_name.'&amp;RefTable='.$filename.'" >'.$filename.'</a></li>'."\n";
            }

            closedir($opened_file);
            $buf .= '</ul>'."\n";
            $buf .= '</li>'."\n";
            $buf .= '<li><a href="index.php?view=RefreshRefData">Refresh Ref Data</a></li>'."\n";
            $buf .= '<li><a href="index.php?view=User_overview">Users</a></li>'."\n";
            $buf .= '<li><a href="index.php?view=Logs">Logs</a></li>'."\n";
            $buf .= '</ul>'."\n";
            $buf .= '</li>'."\n";
        }

        $buf .= '<li><a href="#" >Misc</a>'."\n";
        $buf .= '<ul class="sub_menu">'."\n";
        $buf .= '<li><a href="index.php?view=Find">Search</a></li>'."\n";
        $buf .= '<li><a href="index.php?view=Help">Help</a></li>'."\n";
        $buf .= '<li><a href="index.php?view=Consistency_check">Checks</a></li>'."\n";
        $buf .= '<li><a href="index.php?view=Statistics">Statistics</a></li>'."\n";
        $buf .= '<li><a href="index.php?view=User_ChangePassword">Change Password</a></li>'."\n";
        $buf .= '</ul>'."\n";
        $buf .= '</li>'."\n";
        //LOGOFF
        $buf .= '<li><a href="index.php?view=Logout" >Logout</a></li>'."\n";
        $buf .= '</ul>'."\n";

        $buf .= '</div>'."\n";


        return $buf;
    }



    function error500 ($message){

        //$_SESSION['URLMessage']= $message;

        echo '<script type="text/javascript">'."\n";
        echo '<!--'."\n";
        echo 'window.location = "'.$this->page_view_500.'?URLMessage='.urlencode($message).'"'."\n";


        echo '//-->'."\n";
        echo '</script>'."\n";
        exit;

    }
} //end class
?>